package com.taotao.utils;

import com.alibaba.fastjson.JSONObject;
import com.taotao.entity.UserEntity;

import java.util.HashMap;

/**
 * @author wangjin
 * @title: JvmMapCacheUtils
 * @projectName designmodule
 * @description: TODO
 * @date 2022/6/19 0019 19:41
 */
public class JvmMapCacheUtils<V> {
    private  static HashMap<String, String> cacheMapping=new HashMap<>();
    public static void putEntity(String key,Object object){
        cacheMapping.put(key, JSONObject.toJSONString(object));
    }

    public static <T> T getEntity(String key,Class<T> t){
        String json=cacheMapping.get(key);
        JSONObject jsonObject=JSONObject.parseObject(json);
        return  JSONObject.parseObject(json,t);
    }

    public static void main(String[] args) {
        UserEntity userEntity=new UserEntity(1,"3222",22);
        JvmMapCacheUtils.putEntity("user1",userEntity);
        UserEntity userEntity1=JvmMapCacheUtils.getEntity("user1",UserEntity.class);
        System.out.println(userEntity1);
    }
}
